package com.example.computer_component_manager.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
import com.example.computer_component_manager.R
import com.example.computer_component_manager.bean.Brand

/**
 * 品牌适配器类（用于Spinner）
 * 因品牌只有两个信息：ID、品牌名
 * 因此CPU和显卡公用一个Spinner的适配器类
 *
 * @author 1923111015董寺卓
 */

class BrandAdapter(context: Context, list: List<Brand>) :
    ArrayAdapter<Brand>(context, R.layout.brand_spinner_item, list) {

    override fun getDropDownView(
        position: Int,
        convertView: View?,
        parent: ViewGroup,
    ): View {
        val dropDownView = super.getDropDownView(position, convertView, parent)
        val tvSpinnerBrand = dropDownView.findViewById<TextView>(R.id.tvSpinnerBrand)
        tvSpinnerBrand.text = getItem(position)!!.name
        return dropDownView
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        return getDropDownView(position, convertView, parent)
    }

}